from pyecharts import Line, Bar, Page


class SystemChart:
    def __init__(self, data):
        self.data = data

    def update(self):
        #print(self.data)

        # page = Page()

        header = self.data.columns.values.tolist()
        index = self.data.index.values.tolist()

        bar = Bar(' ')
        for i in range(0, len(header)):
            bar.add(header[i], index, self.data[header[i]].tolist(), is_smooth=True, mark_line=["average"],
                    mark_point=["max"], is_datazoom_show=True, datazoom_range=[0, 100])

        line = Line(' ')
        for i in range(0, len(header)):
            line.add(header[i], index, self.data[header[i]].tolist(), is_smooth=True, mark_line=["average"],
                     mark_point=["max"], is_datazoom_show=True, datazoom_range=[0, 100])

        # page.add_chart(line)
        # page.add_chart(bar)

        return line

    def render(self):
        print(self.data)

        page = Page()

        header = self.data.columns.values.tolist()
        index = self.data.index.values.tolist()

        bar = Bar('DVR Dual Camera Test')
        for i in range(0, len(header)):
            bar.add(header[i], index, self.data[header[i]].tolist(), is_smooth=True, mark_line=["average"],
                    mark_point=["max"], is_datazoom_show=True)

        line = Line('DVR Dual Camera Test')
        for i in range(0, len(header)):
            line.add(header[i], index, self.data[header[i]].tolist(), is_smooth=True, mark_line=["average"],
                     mark_point=["max"], is_datazoom_show=True)

        page.add_chart(bar)
        page.add_chart(line)
        page.render()
